from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import  WebDriverWait
import time

browser=webdriver.Firefox()
browser.get("https://www.12306.cn/index/")
from_id_word="fromStationtext"
to_id_word="toStationText"


from_locator=(By.id,from_id_word)
to_locator=(By.id,to_id_word)
wait=WebDriverWait(browser,10).until(EC.presence_of_all_elements_located(from_locator))
input=browser.find_element_by_id(from_id_word)
input.clear()
input.send_keys("厦门")
browser.find_element_by_id('citem_0').click()
time.sleep(1)

wait=WebDriverWait(browser,10).until(EC.presence_of_all_elements_located(to_locator))
input(browser.find_element_by_id(to_id_word))
input.clear()
input.send_keys("福州")
time.sleep(1)
browser.find_element_by_id('citem_0').click()

date_id_word="train_date"
date_locater=(By.id,date_id_word)
wait=WebDriverWait(browser,10).until(EC.presence_of_all_elements_located(date_locator))
input=browser.find_element_by_id(date_id_word)
input.clear()
input.send_keys("2024-05-01")
time.sleep(1)

btn=browser.find_element_by_xpath('//*[@id="search_one"]')
btn.click()

time.sleep(10)
browser.close()